RE: [GENERAL] How to get seq after insert - Mailing list pgsql-general

From Herouth Maoz
Subject RE: [GENERAL] How to get seq after insert
Date
Msg-id l03130300b3420eefc12a@[147.233.159.109]
Whole thread Raw
In response to RE: [GENERAL] How to get seq after insert  (Michael Davis <michael.davis@tvguide.com>)
List pgsql-general
At 00:39 +0300 on 15/04/1999, Michael Davis wrote:


> The safest way is to select the nextval('seq_name') and then insert using
> this value.

No, actually, this is the unsafest way. This means that the logic is in the
frontend, not the backend. Besides, one can define the sequence as
read-only for the user who uses the database, but write for the one who
created the table that uses it, so that the user can't change the sequence
out of line.

To make a long story short, the best way is to let the insert statement use
the defaulet, and then use currval( 'seq_name' ). This gives you the last
value given in the current session. It is multiuser-safe, etc.

This was on the SQL list a couple of weeks ago. And by the way, the SQL
list is the proper list for this issue.

Herouth

--
Herouth Maoz, Internet developer.
Open University of Israel - Telem project
http://telem.openu.ac.il/~herutma



pgsql-general by date:

Previous
From: Valerio Santinelli
Date:
Subject: Re: [GENERAL] pg_dumpall troubles
Next
From: Karl DeBisschop
Date:
Subject: Re: [GENERAL] problem when vacuuming. . .